package com.miplus.ccrm.report.controller;

import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JSysUser;
import com.miplus.ccrm.common.PageData;
import com.miplus.ccrm.common.R;
import com.miplus.ccrm.report.controller.vo.cti.*;
import com.miplus.ccrm.report.controller.vo.rep.DistCaseNumReqVo;
import com.miplus.ccrm.report.controller.vo.rep.DistCaseNumResVo;
import com.miplus.ccrm.report.controller.vo.rep.RecyAgDayReqVo;
import com.miplus.ccrm.report.controller.vo.rep.RecyAgDayResVo;
import com.miplus.ccrm.report.mapper.ReportCallHistMapper;
import com.miplus.ccrm.report.security.JCommonData;
import com.miplus.ccrm.report.service.cti.CtiCallhistService;
import com.miplus.ccrm.report.service.cti.ReportCallHistService;
import com.miplus.ccrm.report.service.cti.TRecorderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 3-2.CTI报表数据接口
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/call")
public class CallController {
    @Resource
    private JCommonData jCommonData;
    @Resource
    private CtiCallhistService callhistService;

    @Resource
    private TRecorderService tRecorderService;

    @Resource
    private ReportCallHistService reportCallHistService;

    /**
     * 录音查询
     */
    @GetMapping("/recordList")
    public R<PageData<CallResvo>> recordList(@Validated CallReqVo callReqVo){
        JSysUser user= jCommonData.getCurrUsr();
        return R.SuccessPage(tRecorderService.recordList(user,callReqVo));
    }

    /**
     * 呼叫明细查询
     */
    @GetMapping("/callHistList")
    public R<PageData<CallHistResvo>> callHistList(@Validated CallHistReqVo callReqVo){
        JSysUser user= jCommonData.getCurrUsr();
        return R.SuccessPage(reportCallHistService.callHist(user,callReqVo));
    }

    /**
     * 坐席呼叫统计日报
     */
    @GetMapping("/repAgentCallDay")
    public R<PageData<CallAgDayResVo>> repAgentCallDay(@Validated CallAgDayReqVo callReqVo){
        String usrid= jCommonData.getCurrUsrID();
        return R.SuccessPage(reportCallHistService.repAgentCallDay(usrid,callReqVo));
    }

    /**
     * 坐席呼叫统计日报导出
     */
    @PostMapping("/expAgentCallDay")
    public R<CmdResVo> expAgentCallDay(@RequestBody @Validated CallAgDayReqVo callReqVo, HttpServletResponse response){
        String usrid= jCommonData.getCurrUsrID();
        return R.Success(reportCallHistService.expAgentCallDay(usrid,callReqVo,response));
    }

    /**
     * 回收表现统计报表
     */
    @GetMapping("/recoveryTotal")
    public R<PageData<RecyAgDayResVo>> recoveryTotal(@Validated RecyAgDayReqVo recyAgDayReqVo){
        String usrid= jCommonData.getCurrUsrID();
        return R.SuccessPage(reportCallHistService.recoveryTotal(usrid,recyAgDayReqVo));
    }

    /**
     * 回收表现统计报表导出
     */
    @PostMapping("/expRecoveryTotal")
    public R<CmdResVo> expRecoveryTotal(@RequestBody @Validated RecyAgDayReqVo recyAgDayReqVo, HttpServletResponse response){
        String usrid= jCommonData.getCurrUsrID();
        return R.Success(reportCallHistService.expRecoveryTotal(usrid,recyAgDayReqVo,response));
    }

    /**
     * 分配案件数量统计报表
     */
    @GetMapping("/assignTotal")
    public R<PageData<DistCaseNumResVo>> assignTotal(@Validated DistCaseNumReqVo distCaseNumReqVo){
        String usrid= jCommonData.getCurrUsrID();
        return R.SuccessPage(reportCallHistService.assignTotal(usrid,distCaseNumReqVo));
    }

    /**
     * 分配案件数量统计报表导出
     */
    @PostMapping("/expAssignTotal")
    public R<CmdResVo> expAssignTotal(@RequestBody @Validated DistCaseNumReqVo distCaseNumReqVo, HttpServletResponse response){
        String usrid= jCommonData.getCurrUsrID();
        return R.Success(reportCallHistService.expAssignTotal(usrid,distCaseNumReqVo,response));
    }
    /**
     * 取坐席录音翻译对话List
     */
    @GetMapping("/quyAgentDialogue")
    public R<List<DialogueResVo>> quyAgentDialogue(@Validated DialogueReqVo reqVo){
        return R.Success(tRecorderService.quyAgentDialogue(reqVo.getCallid(),reqVo.getAgentid()));
    }

    /**
     * 取机Ivr翻译对话List
     */
    @GetMapping("/quyIvrDialogue")
    public R<List<DialogueResVo>> quyIvrDialogue(@RequestParam @NotNull String callid){
        return R.Success(tRecorderService.quyIvrDialogue(callid));
    }
}
